#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
        stack<int> num;
        int m = pushed.size(), n = popped.size();
        int i = 0, j = 0;
        while (i < m) {
            num.push(pushed[i]);
            while (!num.empty() && num.top() == popped[j])
            {
                num.pop();
                j++;
            }
            i++;
        }
        if (j < n) return false;
        return true;
    }
};